import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//解决按下两次相同路由跳转逻辑报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const Main = () => import('../views/Main.vue')
const Home = () => import('../views/home/Home.vue')
const User = () => import('../views/user/User.vue')
const VideoManage = () => import('../views/videomanage/VideoManage.vue')
const Page1 = () => import('../views/other/Page1.vue')
const Page2 = () => import('../views/other/Page2.vue')

const Login = () => import('../views/login/Login.vue')

const routes = [
  {
    path: '',
    redirect: '/login'
    // redirect: 'main/home'
  },
  {
    path: '/main',
    name: 'Main',
    component: Main,
    children: [
      {
        path: 'home',
        name: 'home',
        component: Home
      },
      {
        path: 'user',
        name: 'user',
        component: User
      },
      {
        path: 'video',
        name: 'video',
        component: VideoManage
      },
      {
        path: 'other/page1',
        name: 'page1',
        component: Page1
      },
      {
        path: 'other/page2',
        name: 'page2',
        component: Page2
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  }
]

const router = new VueRouter({
  // 取消history避免打包后空白的问题
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
